﻿using System;
using System.Drawing;
using System.Windows.Data;

namespace FishSimulation.Converters {
    [ValueConversion(typeof(string), typeof(System.Drawing.Image))]
    public class Base64StringToImageConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            if (value is string) {
                return Utils.Base64ToImage(value.ToString());
            }
            return Binding.DoNothing;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            if (value is Image) {
                return Utils.ImageToBase64((Image)value, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            return Binding.DoNothing;
        }
    }
}
